#include<bits/stdc++.h>
#include <vector>
using namespace std;
const int maxn = 100000;
vector<int> ways[maxn];
int col[maxn],path[maxn],n,m,root;
vector<int> result;
bool flag;
inline void init() {
    memset(col,-1,sizeof(col));
    memset(path,-1,sizeof(path));
    result.clear();
    flag = true;
    for(int i=0;i<maxn;i++) ways[i].clear();
}
inline void addedge(int u,int v) {
    ways[u].push_back(v);
    ways[v].push_back(u);
}
void dfs(int rt,int c) {
    if(!flag) return ;
    col[rt] = c;
    for(int i=0;i<ways[rt].size();i++) {
        if(!flag) return;
        if(col[ways[rt][i]] == -1) {
            path[ways[rt][i]] = rt;
            dfs(ways[rt][i],c^1);
        }
        else {
            if(col[ways[rt][i]] == c) {
                path[ways[rt][i]] = rt;
                flag = false;
                root = ways[rt][i];
                return;
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m)) {
        init();
        for(int i=0,u,v;i<m;i++) {
            scanf("%d%d",&u,&v);
            addedge(u,v);
        }
        dfs(1,0);
        if(flag) {
            printf("0\n");
            for(int i=1;i<n;i++) printf("%d ",col[i]);printf("%d\n",col[n]);
        }
        else {
            int now = path[root];
            result.push_back(root);
            while(root != now) {
                result.push_back(now);
                now = path[now];
            }
            int k = result.size();
            printf("%d\n",k);
            for(int i=0;i<k-1;i++) printf("%d ",result[i]);printf("%d\n",result[k-1]);
        }
    }
    return 0;
}
